package com.itboye.ihomebank.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.bean.BindCardsList;
import com.itboye.ihomebank.support.commonadapter.MutiplyCommonAdapter;
import com.itboye.ihomebank.support.commonadapter.ViewHolder;

import java.util.HashMap;
import java.util.List;

/**
 * 账户银行卡
 * 
 */
public class ZhangHuAdapter extends MutiplyCommonAdapter<BindCardsList> {
	int position;
	List<BindCardsList> list;
	HashMap<String, Bitmap> hashMap = new HashMap<>();

	public ZhangHuAdapter(Context context, List<BindCardsList> datas,
			int... layoutId) {
		super(context, datas, layoutId);
		list = datas;
		hashMap.put("北京银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.beijing_bank));
		hashMap.put("工商银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.gongshang_bank));
		hashMap.put("广发银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.guangfa_bank));
		hashMap.put("广州银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.guangzhou_bank));
		hashMap.put("广州农商银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.guangzhounongshang_bank));
		hashMap.put("花旗银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.huaqi_bank));
		hashMap.put("华夏银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.huaxia_bank));
		hashMap.put("建设银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.jianshe_bank));
		hashMap.put("交通银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.jiaotong_bank));
		hashMap.put("民生银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.minsheng_bank));
		hashMap.put("农业银行", BitmapFactory.decodeResource(context.getResources(),
				R.drawable.nongye_bankl));
		hashMap.put("平安银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.pingan_bank));
		hashMap.put("浦发银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.pufa_bank));
		hashMap.put("浦东发展银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.pufa_bank));
		hashMap.put("深圳发展银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.shenzhenfazhan_bank));
		hashMap.put("兴业银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.xingye_bank));
		hashMap.put("邮政储蓄银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.youzheng_bank));
		hashMap.put("招商银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.zhaoshang_bank));
		hashMap.put("中国银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.zhongguo_bank));
		hashMap.put("中兴银行", BitmapFactory.decodeResource(
				context.getResources(), R.drawable.zhongxin_bank));
	}

	@Override
	public int getItemViewType(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void getItemPosition(int position) {
		this.position = position;

	}

	@Override
	public void convert(ViewHolder holder, BindCardsList t, int type,
			int position) {
		// TODO Auto-generated method stub
		holder.setImageBitmap(R.id.item_zhanghu_img,
				hashMap.get(t.getBank().get(0)));
		holder.setText(R.id.bank_type, t.getBank().get(0));
		holder.setText(R.id.card_type, t.getBank().get(1).equals("贷记卡")?"信用卡":t.getBank().get(1));
		// holder.setBackgroundRes(viewId, backgroundRes)

		String num=t.getBankNo();//银行卡号
		if(num.length()>4){
			String s=num.substring(num.length()-4, num.length());//后四位
			String ss=num.substring(0, num.length()-4);//后四位
			StringBuffer sb=new StringBuffer();
			for (int i=0;i<ss.length();i++){
				sb.append("*");
			}
			holder.setText(R.id.item_zhanghu_num, sb+s);
		}else{
			holder.setText(R.id.item_zhanghu_num, t.getBankNo());
		}
	}

}
